Telegram Group & Telegram Channel
📊 Шпаргалка по Python-профайлингу: как найти узкие места в коде

Разбираем 4 мощных инструмента для анализа производительности и памяти в Python.

🧠 `cProfile` — встроенный профайлер времени

Показывает, сколько времени тратится на каждую функцию
Идеально для быстрого анализа


python -m cProfile your_script.py


Форматированный вывод с pstats:


python -m cProfile -o result.prof your_script.py
python -m pstats result.prof


Для Jupyter:


%load_ext cprofile
%cprofile some_function()


🐍 py-spy — суперлёгкий sampling-профайлер

Не требует изменений в коде
Работает с чужими процессами
Без тормозов, можно запускать в проде


py-spy top --pid <PID>
py-spy record -o profile.svg -- python your_script.py


👉 Показывает flame graph: удобная визуализация bottleneck-функций.

🔥 `Scalene` — профайлинг CPU, памяти и аллокаций

Отслеживает:
- сколько времени тратит CPU
- где происходят аллокации
- сколько памяти реально используется


pip install scalene
scalene your_script.py


👉 Выделяет проблемные строки, показывает выделение памяти по строчкам кода, а не только по функциям.

🧮 `memory_profiler` — анализ использования памяти

Показывает, сколько памяти потребляет каждая строка
Полезен для data science скриптов


pip install memory-profiler


Добавь декоратор:


from memory_profiler import profile

@profile
def my_func():
...


Запуск:


python -m memory_profiler your_script.py


💡 Как выбрать?

| Инструмент | Что профилирует | Подходит для |
|--------------------|----------------------|------------------------------|
| `cProfile` | Время (встроенно) | Быстрый старт, базовый анализ |
| `py-spy` | Время (sampling) | Прод, чужие процессы, flame graphs |
| `Scalene` | Время + память + аллокации | Глубокий анализ по строкам |
| `memory_profiler` | Только память | Data science, отладка RAM |



tg-me.com/pro_python_code/1823
Create:
Last Update:

📊 Шпаргалка по Python-профайлингу: как найти узкие места в коде

Разбираем 4 мощных инструмента для анализа производительности и памяти в Python.

🧠 `cProfile` — встроенный профайлер времени

Показывает, сколько времени тратится на каждую функцию
Идеально для быстрого анализа


python -m cProfile your_script.py


Форматированный вывод с pstats:


python -m cProfile -o result.prof your_script.py
python -m pstats result.prof


Для Jupyter:


%load_ext cprofile
%cprofile some_function()


🐍 py-spy — суперлёгкий sampling-профайлер

Не требует изменений в коде
Работает с чужими процессами
Без тормозов, можно запускать в проде


py-spy top --pid <PID>
py-spy record -o profile.svg -- python your_script.py


👉 Показывает flame graph: удобная визуализация bottleneck-функций.

🔥 `Scalene` — профайлинг CPU, памяти и аллокаций

Отслеживает:
- сколько времени тратит CPU
- где происходят аллокации
- сколько памяти реально используется


pip install scalene
scalene your_script.py


👉 Выделяет проблемные строки, показывает выделение памяти по строчкам кода, а не только по функциям.

🧮 `memory_profiler` — анализ использования памяти

Показывает, сколько памяти потребляет каждая строка
Полезен для data science скриптов


pip install memory-profiler


Добавь декоратор:


from memory_profiler import profile

@profile
def my_func():
...


Запуск:


python -m memory_profiler your_script.py


💡 Как выбрать?

| Инструмент | Что профилирует | Подходит для |
|--------------------|----------------------|------------------------------|
| `cProfile` | Время (встроенно) | Быстрый старт, базовый анализ |
| `py-spy` | Время (sampling) | Прод, чужие процессы, flame graphs |
| `Scalene` | Время + память + аллокации | Глубокий анализ по строкам |
| `memory_profiler` | Только память | Data science, отладка RAM |

BY Python RU


Warning: Undefined variable $i in /var/www/tg-me/post.php on line 283

Share with your friend now:
tg-me.com/pro_python_code/1823

View MORE
Open in Telegram


Python RU Telegram | DID YOU KNOW?

Date: |

Export WhatsApp stickers to Telegram on iPhone

You can’t. What you can do, though, is use WhatsApp’s and Telegram’s web platforms to transfer stickers. It’s easy, but might take a while.Open WhatsApp in your browser, find a sticker you like in a chat, and right-click on it to save it as an image. The file won’t be a picture, though—it’s a webpage and will have a .webp extension. Don’t be scared, this is the way. Repeat this step to save as many stickers as you want.Then, open Telegram in your browser and go into your Saved messages chat. Just as you’d share a file with a friend, click the Share file button on the bottom left of the chat window (it looks like a dog-eared paper), and select the .webp files you downloaded. Click Open and you’ll see your stickers in your Saved messages chat. This is now your sticker depository. To use them, forward them as you would a message from one chat to the other: by clicking or long-pressing on the sticker, and then choosing Forward.

The S&P 500 slumped 1.8% on Monday and Tuesday, thanks to China Evergrande, the Chinese property company that looks like it is ready to default on its more-than $300 billion in debt. Cries of the next Lehman Brothers—or maybe the next Silverado?—echoed through the canyons of Wall Street as investors prepared for the worst.

Python RU from de


Telegram Python RU
FROM USA